import QtQuick 2.15
import QtQml.Models 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15

import org.ukui.systemTray 1.0
import org.ukui.quick.items 1.0
import org.ukui.quick.views 1.0
import org.ukui.quick.types 1.0

ContentWindow {
    margin.bottom: 8
    margin.right: 50
    position: Position.BottomRight

//    property alias folderModel: foldGroupModel
    property int folderCount: gridview.count
    property int folderBeginIndex: -1
    signal folderDragFinshed()
    signal folderDragStart(int startIndex)

    DropArea {
        width: 200
        height: 200
        property var dragIndex
        property var itemsIndex
        GridView {
            id: gridview
            interactive: false
            width: 200
            height: 200
            cellWidth: 50; cellHeight: 50
            property int dragStartIndex: -1

            model: DelegateModel {
                id: visualModel
                model: folderGroup
                delegate: IconDelegate {
                    trayGroups: "folder"
                    trayIcon: model.Icon
                    order: DelegateModel.itemsIndex
//                    onEntered: drag => {
//                                  visualModel.items.move(drag.source.draggableOrder, order)
//                               }

                    onDragStart: startIndex => {
                        gridview.dragStartIndex = startIndex;
                        folderDragStart(startIndex);
                    }

                    onDragFinshed: {
                        ItemModel.setOrderInGroup(folderGroup, folderGroup.index(gridview.dragStartIndex, 0), order);
                        folderDragFinshed();
                    }
                }
            }
            Component.onCompleted: {
                folderGroup.setSourceModel(ItemModel);
                folderGroup.setGroupBegin(folderBeginIndex);
                folderGroup.setGroupEnd(7)
            }
        }
    }
}
